﻿#include "HRibbonElementCreateDelegate.h"
#include "HRibbonBar.h"
#include "HRibbonApplicationButton.h"
#include "HRibbonTabBar.h"
#include "HRibbonCategory.h"
#include "HRibbonContextCategory.h"
#include "HRibbonPannel.h"
#include "HRibbonSeparatorWidget.h"
#include "HRibbonGallery.h"
#include "HRibbonGalleryGroup.h"
#include "HRibbonToolButton.h"
#include "HRibbonControlButton.h"
#include "HRibbonButtonGroupWidget.h"
#include "HRibbonStackedWidget.h"
#include "HRibbonQuickAccessBar.h"
#include "HRibbonPannelOptionButton.h"
#include "HRibbonPannelLayout.h"


HRibbonStyleOption::HRibbonStyleOption()
{
    mainbarHeightOfficeStyleThreeRow = 160;
    mainbarHeightWPSStyleThreeRow = 130;
    mainbarHeightOfficeStyleTwoRow = 134;
    mainbarHeightWPSStyleTwoRow = 104;
    widgetBord = QMargins(5, 1, 5, 5);
    titleBarHight = 30;
    titleTextColor = Qt::white;
    tabBarHight = 25;
    tabBarBaseLineColor = QColor(186, 201, 219);
    applicationButtonWidth = 60;
    galleryFixedHeight = 60;
    galleryMinimumWidth = 120;
    galleryButtonMaximumWidth = 15;
    pannelTitleHeight = 21;
    toolButtonLargeIconSize = QSize(32, 32);
    toolButtonSmallIconSize = QSize(18, 18);
}


HRibbonElementCreateDelegate::HRibbonElementCreateDelegate()
    : m_opt(new HRibbonStyleOption())
{
}


HRibbonElementCreateDelegate::~HRibbonElementCreateDelegate()
{
    if (m_opt) {
        delete m_opt;
    }
    m_opt = nullptr;
}


HRibbonTabBar *HRibbonElementCreateDelegate::createRibbonTabBar(QWidget *parent)
{
    return (new HRibbonTabBar(parent));
}


HRibbonApplicationButton *HRibbonElementCreateDelegate::createRibbonApplicationButton(QWidget *parent)
{
    return (new HRibbonApplicationButton(parent));
}


HRibbonCategory *HRibbonElementCreateDelegate::createRibbonCategory(QWidget *parent)
{
    return (new HRibbonCategory(parent));
}


HRibbonContextCategory *HRibbonElementCreateDelegate::createRibbonContextCategory(QWidget *parent)
{
    return (new HRibbonContextCategory(parent));
}


HRibbonPannel *HRibbonElementCreateDelegate::createRibbonPannel(QWidget *parent)
{
    return (new HRibbonPannel(parent));
}


HRibbonSeparatorWidget *HRibbonElementCreateDelegate::createRibbonSeparatorWidget(int value, QWidget *parent)
{
    return (new HRibbonSeparatorWidget(value, parent));
}


HRibbonSeparatorWidget *HRibbonElementCreateDelegate::createRibbonSeparatorWidget(QWidget *parent)
{
    return (new HRibbonSeparatorWidget(parent));
}


HRibbonGallery *HRibbonElementCreateDelegate::createRibbonGallery(QWidget *parent)
{
    return (new HRibbonGallery(parent));
}


HRibbonGalleryGroup *HRibbonElementCreateDelegate::createRibbonGalleryGroup(QWidget *parent)
{
    return (new HRibbonGalleryGroup(parent));
}


HRibbonToolButton *HRibbonElementCreateDelegate::createRibbonToolButton(QWidget *parent)
{
    return (new HRibbonToolButton(parent));
}


HRibbonStackedWidget *HRibbonElementCreateDelegate::createRibbonStackedWidget(HRibbonBar *parent)
{
    return (new HRibbonStackedWidget(parent));
}


HRibbonControlButton *HRibbonElementCreateDelegate::createHidePannelButton(HRibbonBar *parent)
{
    HRibbonControlButton *btn = new HRibbonControlButton(parent);

    btn->setAutoRaise(false);
    btn->setObjectName(QStringLiteral("HRibbonBarHidePannelButton"));
    btn->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btn->setFixedSize(parent->tabBarHeight()-4, parent->tabBarHeight()-4);
    return (btn);
}


HRibbonButtonGroupWidget *HRibbonElementCreateDelegate::craeteButtonGroupWidget(QWidget *parent)
{
    return (new HRibbonButtonGroupWidget(parent));
}


HRibbonQuickAccessBar *HRibbonElementCreateDelegate::createQuickAccessBar(QWidget *parent)
{
    return (new HRibbonQuickAccessBar(parent));
}


const HRibbonStyleOption& HRibbonElementCreateDelegate::getRibbonStyleOption() const
{
    return (*m_opt);
}


/**
 * @brief 设置style配置类，HRibbonElementCreateDelegate将保留HRibbonStyleOption的所有权
 * @param opt
 */
void HRibbonElementCreateDelegate::setRibbonStyleOption(HRibbonStyleOption *opt)
{
    if (m_opt) {
        delete m_opt;
    }
    m_opt = opt;
}


/**
 * @brief 创建HRibbonPannelOptionButton
 * @param pannel 附属的pannel
 * @return
 * @sa @ref HRibbonPannelOptionButton
 */
HRibbonPannelOptionButton *HRibbonElementCreateDelegate::createRibbonPannelOptionButton(HRibbonPannel *pannel)
{
    return (new HRibbonPannelOptionButton(pannel));
}
